
<?php
    include "../database.php";
    
    
    $admin=$_POST["role"];
    $username=$_POST["username"];
    $name=$_POST["first_name"];
    $last_name=$_POST["last_name"];
    $email=$_POST["email"];
    $pass1=$_POST["password"];
    $pass2=$_POST["password_confirm"];
    
    //echo "<h1> $username, $name, $last_name, $email, $pass1, $pass2, $admin </h1>";
    $query = "SELECT * FROM user WHERE username='$username'";
    $result = executeQuery($query);
    
    $msg_id=-1;
    $success = 0;
    if(mysql_num_rows($result)==0){  //Preverjamo, koliko je ze uporabnikov s takim idjem, ce se ni nobenega, potem ga lahko dodamo
        if($pass1==$pass2){
            $query = "INSERT INTO `TPO15_2013`.`user` (`id`, `username`, `name`, `last_name`, `mail`, `pass`, `admin`) VALUES (NULL, '$username', '$name', '$last_name', '$email', '$pass1', '$admin')";
            executeQuery($query);
            
            $msg_id=201;
            $array = array('msg' => message($msg_id).' '.$username, 'success' => '1');
            echo json_encode($array);
        }
        else{ 
            $msg_id=102;
            $array = array('msg' => message($msg_id), 'success' => '0');
            echo json_encode($array);
        }
    }
    else{
        $msg_id=101;
        $array = array('msg' => message($msg_id), 'success' => '0');
        echo json_encode($array);
    }
    
?>

